package com.briup.MR.InOutFormat;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;

import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.CombineTextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

/**
 * yarn jar HdfsClientDemo-1.0-SNAPSHOT.jar com.briup.MR.InOutFormat.CombineMR -D input=/user/hdfs/indexcount -D output=/user/hdfs/com_result
 */
public class CombineMR extends Configured implements Tool {
    public int run(String[] strings) throws Exception {
        Configuration conf = getConf();
        String input = conf.get("input");
        String output = conf.get("output");

        Job job = Job.getInstance(conf);
        job.setJarByClass(this.getClass());
        job.setJobName("CombineMR");



        //不针对Gzip，Gzip不能拆分
        //CombineFileInputFormat读取一行内容产生一个键值
        //键是偏移位置，值是整行内容
        CombineTextInputFormat.setMaxInputSplitSize(job,1024*1024*1024);
        CombineTextInputFormat.setMinInputSplitSize(job,1024);
        job.setInputFormatClass(CombineTextInputFormat.class);
        CombineTextInputFormat.addInputPath(job,new Path(input));
        TextOutputFormat.setOutputPath(job,new Path(output));
        return job.waitForCompletion(true)?0:-1;
    }

    public static void main(String[] args) throws Exception {
        System.exit(new ToolRunner().run(new CombineMR(),args));
    }
}
